package com.bdqn.ordersystem.controller;

import com.bdqn.ordersystem.pojo.Area;
import com.bdqn.ordersystem.pojo.Center;
import com.bdqn.ordersystem.pojo.Order;
import com.bdqn.ordersystem.service.AreaService;
import com.bdqn.ordersystem.service.CenterService;
import com.bdqn.ordersystem.service.OrderService;
import com.bdqn.ordersystem.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class IndexController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private CenterService centerService;
    @Autowired
    private AreaService areaService;
    /**
     * 首页
     * @return
     */
    @RequestMapping("/index")
    public String home(){
        return "home/index";
    }

    /**
     * 待处理清单
     * @return
     */
    @RequestMapping("/dolist")
    public String dolist(Model model,Integer areaId, Integer centerId, String address, Integer pageIndex, Integer pageSize){
        Pager<Order> pagers = orderService.listByPage1(areaId, centerId, address, pageIndex, 10);
        model.addAttribute("pagers",pagers);
        model.addAttribute("areas",areaService.listAll());
        if(null!=areaId){
            model.addAttribute("areaId",areaId);
        }
        if(null!=centerId){
            model.addAttribute("centerId",centerId);
        }
        if(null!=address & ""!=address){
            model.addAttribute("address",address);
        }
        return "/handle/dolist";
    }

    /**
     * 路线规划
     * @return
     */
    @RequestMapping("/map")
    public String map(){
        return "handle/map";
    }
    @GetMapping("/plans")
    public String plans(){
        return "handle/plans";
    }
    /**
     * 在途工单
     * @return
     */
    @GetMapping("/plan")
    @ResponseBody
    public Object plans(Integer areaId, Integer centerId, String address, Integer pageIndex, Integer pageSize){
        Pager<Order> pagers = orderService.listByPage(areaId, centerId, address, pageIndex, 10);
        return pagers;
    }
    @GetMapping("/getArea")
    @ResponseBody
    public Object getArea(){
        List<Area> areas = areaService.listAll();
        return areas;
    }
    @RequestMapping("/getCenters")
    @ResponseBody
    public Object getCenter(Integer areaId){
        List<Center> centers = centerService.listByAreaId(areaId);
        return centers;
    }

    @RequestMapping("/dowork")
    public String dowork(){
        return "/handle/dowork";
    }

    /**
     * 历史完成工单
     * @return
     */
    @RequestMapping("/historys")
    public String history(){
        return "handle/historys";
    }

    @RequestMapping("/allorder")
    public String allorder(){
        return "/handle/allorder";
    }

}
